// ReadOSC.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include <iostream>

#include "../osc/OscReceivedElements.h"
#include "../osc/OscPacketListener.h"
#include "../ip/UdpSocket.h"


#define PORT 7000

class ExamplePacketListener : public osc::OscPacketListener {
protected:

    virtual void ProcessMessage( const osc::ReceivedMessage& m, 
				const IpEndpointName& remoteEndpoint )
    {
        try{
            // example of parsing single messages. osc::OsckPacketListener
            // handles the bundle traversal.
            
            if( strcmp( m.AddressPattern(), "/face" ) == 0 ){
                osc::ReceivedMessageArgumentStream args = m.ArgumentStream();
                osc::int32 x;
                osc::int32 y;
                osc::int32 radius;
                args >> x >> y >> radius >> osc::EndMessage;
                
                std::cout << "received '/face' message with arguments: "
                    << x << " " << y << " " << radius << " \n";
                
            } else if( strcmp( m.AddressPattern(), "/blob" ) == 0 ){
                osc::ReceivedMessageArgumentStream args = m.ArgumentStream();
                osc::int32 x;
                osc::int32 y;
                osc::int32 radius;
                args >> x >> y >> radius >> osc::EndMessage;
                
                std::cout << "received '/blob' message with arguments: "
                    << x << " " << y << " " << radius << " \n";
            }
        }catch( osc::Exception& e ){
            // any parsing errors such as unexpected argument types, or 
            // missing arguments get thrown as exceptions.
            std::cout << "error while parsing message: "
                << m.AddressPattern() << ": " << e.what() << "\n";
        }
    }
};

int _tmain(int argc, _TCHAR* argv[])
{
    ExamplePacketListener listener;
    UdpListeningReceiveSocket s(
            IpEndpointName( IpEndpointName::ANY_ADDRESS, PORT ),
            &listener );

    std::cout << "press ctrl-c to end\n";

    s.RunUntilSigInt();

    return 0;
}